import random
fname = 'chance_mod.dat'
f = open(fname, 'w')
random.seed(1000)
f.write('\n')

#f.write('hello, world' + '\n')
#f.write('second line')
def write_set(name, data, file):
    f = file
    size = len(data)
    f.write('set' + ' ' + name + ' ' + ':='+' ')
    for i in range(size):
        f.write(data[i] + ' ')
    f.write(';'+'\n\n')

def write_param_0d(name, data, file):
    f = file
    f.write('param' + ' ' + name + ' ' + ':='+' ')
    f.write(str(data))
    f.write(';'+'\n\n')

def write_param_1d(name, set, data, file, njust = 10, prec=6):
    f = file
    size = len(set)
    entry = 0
    f.write('param' + ' ' + name + ' ' + ':='+'\n')
    for i in range(size):
        if isinstance(data[i], int):
            entry = data[i]
        else:
            entry = round(data[i], prec)
        f.write(set[i].ljust(njust) + ' ' + str( entry ) + '\n')
    f.write(';'+'\n\n')

def write_param_2d(name, set_x, set_y, data, file, njust = 10, prec = 6):
    f = file
    entry = 0
    row_size = len(set_x)
    col_size = len(set_y)

    f.write('param' + ' ' + name + ' ' + ':'+'\n')
    f.write(' '.rjust(njust+1))

    for j in range(col_size):
        f.write(set_y[j].rjust(njust) + ' ')
    f.write(':= ' + '\n')

    for i in range(row_size):
        f.write(set_x[i].ljust(njust) + ' ')
        for j in range(col_size):
            if isinstance(data[i][j], int):
                entry = data[i][j]
            else:
                entry = round(data[i][j], prec)

            f.write(str(entry).rjust(njust) + ' ')
        f.write('\n')

    f.write(';'+'\n\n')

NI = 100
NJ = 50

I = ['i' + str(i+1) for i in range(NI)]
write_set('I', I, f)

J = ['j' + str(j+1) for j in range(NJ)]
write_set('J', J, f)

A = [ [random.uniform(0.5,1) for i in range(NI)] for j in range(NJ)]
write_param_2d('A', J, I , A, f)

b = [random.uniform(NI,5*NI)  for j in range(NJ) ]
write_param_1d('b', J, b, f) 

c = [random.uniform(1,1)  for i in range(NI) ]
write_param_1d('c', I, c, f) 

p = [random.uniform(0,1)  for j in range(NJ) ]    
ps = sum(p)
for i in range(len(p)):
    p[i] = p[i]/ps
write_param_1d('p', J, p, f) 

bigm = [50] * NJ
write_param_1d('bigm', J, bigm, f) 

alpha = 0.6
write_param_0d('alpha', alpha, f)
